import { DataEvent } from "../../../events/DataEvent";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { EventName } from "../../../mvc/EventName";
import { Cache } from "../../../cache/Cache";
import { SWFInfo } from "../../../../../com/gengine/resource/info/SWFInfo";
import { ResouceConst } from "../../../../component/gconst/ResouceConst";
import { ImagesConst } from "../../../resource/ImagesConst";
import { LoaderManager } from "../../../../../com/gengine/resource/LoaderManager";
import { GlobalClass } from "../../../../../com/mui/core/GlobalClass";
import { TilePanel } from "../../equipment/TilePanel";
import { ScrollPolicy } from "../../../../../fl/controls/ScrollPolicy";
import { DailyItemRenderer } from "../../daily/reward/DailyItemRenderer";
import { DataProvider } from "../../../../../fl/data/DataProvider";
import { GiftConfig } from "../../../resource/GiftConfig";
import { DailyRule } from "../../../rules/DailyRule";
import { GButton } from "../../../../../com/mui/controls/GButton";
import { Language } from "../../../../../extend/language/Language";
import { FilterConst } from "../../../../component/gconst/FilterConst";
import { ScaleBitmap } from "../../../../../com/mui/display/ScaleBitmap";
type int = number;
//class GuideVIPGiftPanel
    
    export  class GuideVIPGiftPanel /* flash.display.Sprite */
    {
        constructor(arg1: int, arg2: int)
        {
            
            this._width = arg1;
            this._height = arg2;
            this.init();
            addEventListener(flash.events.Event.ADDED_TO_STAGE, this.onAddToStageHandler);
            return;
        }

        /* internal  */onPlayerHavePayHandler(arg1: DataEvent): void
        {
            var loc1=arg1.data as int;
            if (loc1 > 0) 
            {
                this._getGiftBtn.enabled = true;
            }
            return;
        }

        /* internal  */onAddToStageHandler(arg1: Object /* flash.events.Event */): void
        {
            addEventListener(flash.events.Event.REMOVED_FROM_STAGE, this.onRemoveFromStageHandler);
            Dispatcher.addEventListener(EventName.HavePay, this.onPlayerHavePayHandler);
            if (Cache.instance.role.recharge > 0) 
            {
                this._getGiftBtn.enabled = true;
            }
            else 
            {
                this._getGiftBtn.enabled = false;
            }
            return;
        }

        /* internal  */onRemoveFromStageHandler(arg1: Object /* flash.events.Event */): void
        {
            removeEventListener(flash.events.Event.REMOVED_FROM_STAGE, this.onRemoveFromStageHandler);
            Dispatcher.removeEventListener(EventName.HavePay, this.onPlayerHavePayHandler);
            return;
        }

        /* internal  */onRechargeClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.GotoPay));
            return;
        }

        /* internal  */onGetGiftBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.NovicePackGet, 3));
            return;
        }

        /* internal  */onFontMcLoadedHandler(arg1: SWFInfo): void
        {
            if (arg1 && arg1.clip) 
            {
                this._fontMc = arg1.clip;
                this._fontMc.x = 10;
                this._fontMc.y = 10;
                addChild(this._fontMc);
            }
            return;
        }

        /* internal  */init(): void
        {
            var loc3=null;
            var loc5=null;
            this._middleBg = ResouceConst.getScaleBitmap(ImagesConst.WindowCenterB);
            this._middleBg.width = this._width;
            this._middleBg.height = this._height;
            addChild(this._middleBg);
            LoaderManager.instance.load("guideVIPGiftFont.swf", this.onFontMcLoadedHandler);
            var loc1=0;
            var loc2=11;
            while (loc1 <= loc2) 
            {
                loc3 = GlobalClass.getBitmap(ImagesConst.PackItemBg);
                loc3.x = 8 + Math.floor(loc1 % 6) * 46;
                loc3.y = 43 + Math.floor(loc1 / 6) * 46;
                addChild(loc3);
                ++loc1;
            }
            this._itemList = new TilePanel();
            this._itemList.rowHeight = 46;
            this._itemList.columnWidth = 46;
            this._itemList.horizontalGap = 0;
            this._itemList.verticalGap = 0;
            this._itemList.setSize(300, 100);
            this._itemList.horizontalScrollPolicy = ScrollPolicy.OFF;
            this._itemList.verticalScrollPolicy = ScrollPolicy.OFF;
            this._itemList.setStyle("skin", new Object /* flash.display.Bitmap */());
            this._itemList.setStyle("cellRenderer", DailyItemRenderer);
            this._itemList.x = 11;
            this._itemList.y = 46;
            this._itemList.mouseEnabled = false;
            addChild(this._itemList);
            this._dataProvider = new DataProvider();
            var loc4;
            if (loc4 = GiftConfig.instance.getInfoByType(DailyRule.GiftNovicePack3)) 
            {
                loc1 = 0;
                loc2 = loc4.items.length;
                while (loc1 < loc2) 
                {
                    loc5 = loc4.items[loc1];
                    this._dataProvider.addItem(loc5);
                    ++loc1;
                }
                this._itemList.dataProvider = this._dataProvider;
            }
            this._rechargeBtn = new GButton();
            this._rechargeBtn.label = Language.getString(21100);
            this._rechargeBtn.setSize(75, 22);
            this._rechargeBtn.x = 300;
            this._rechargeBtn.y = 50;
            this._rechargeBtn.styleName = "ButtonSpecial";
            this._rechargeBtn.textField.filters = [FilterConst.nameGlowFilter];
            this._rechargeBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onRechargeClickHandler);
            addChild(this._rechargeBtn);
            this._getGiftBtn = new GButton();
            this._getGiftBtn.label = Language.getString(21101);
            this._getGiftBtn.setSize(75, 22);
            this._getGiftBtn.x = this._rechargeBtn.x;
            this._getGiftBtn.y = 95;
            this._getGiftBtn.styleName = "ButtonSpecial";
            this._getGiftBtn.textField.filters = [FilterConst.nameGlowFilter];
            this._getGiftBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onGetGiftBtnClickHandler);
            addChild(this._getGiftBtn);
            return;
        }

        public /* override */ get height(): number
        {
            return this._height;
        }

        public /* override */ get width(): number
        {
            return this._width;
        }

        /* internal */ /* var */_middleBg: ScaleBitmap;

        /* internal */ /* var */_width: int;

        /* internal */ /* var */_height: int;

        /* internal */ /* var */_rechargeBtn: GButton;

        /* internal */ /* var */_getGiftBtn: GButton;

        /* internal */ /* var */_fontMc: Object /* flash.display.MovieClip */;

        protected /* var */_itemList: TilePanel;

        protected /* var */_dataProvider: DataProvider;
    }
